#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
using namespace std;

int main()
{
	int n,m,k,w;
	cin>>n>>m>>k>>w;

	vector<vector<string>> vvs;
	list<pair<int,int>> ways;
	int total = 0;
	for (int i = 1; i <= k; ++i)
	{
		vector<string> vs;
		for (int j = 0; j < n; ++j)
		{
			string s;
			cin>>s;
			vs.push_back(s);
		}

		int idx = -1;
		int bytes = n*m;
		for (int j = 0; j < vvs.size(); ++j)
		{
			vector<string> prev = vvs[j];

			int cnt = 0;
			for (int p = 0; p < n; ++p)
				for (int q = 0; q < m; ++q)
					if (prev[p][q] != vs[p][q])
						++cnt;

			if (cnt*w < bytes)
			{
				bytes = cnt*w;
				idx = j+1;
			}
		}

		if (idx != -1)
		{
			auto it = ways.begin();
			while (it != ways.end())
			{
				if (it->first == idx)
				{
					++it;
					while (it != ways.end() && it->second == idx)
						++it;
					break;
				}
				++it;
			}

			ways.insert(it, make_pair(i, idx));
			total += bytes;
		}
		else
		{
			ways.push_back(make_pair(i, 0));
			total += bytes;
		}

		vvs.push_back(vs);
	}

	cout<<total<<endl;
	auto it = ways.begin();
	while (it != ways.end())
	{
		cout<<it->first<<" "<<it->second<<endl;
		++it;
	}

}